package cn.yx.common.core.enums.http;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Http请求头枚举</p>
 *
 * @author Wgssmart
 */
public enum HttpHeaderEnum {

    /**
     * User-Agent
     */
    USER_AGENT("User-Agent", "User-Agent"),
    /**
     * Content-Type
     */
    CONTENT_TYPE("Content-Type", "Content-Type"),
    /**
     * Content-Length
     */
    CONTENT_LENGTH("Content-Length", "Content-Length"),
    /**
     * Accept
     */
    ACCEPT("Accept", "Accept"),
    /**
     * Accept-Encoding
     */
    ACCEPT_ENCODING("Accept-Encoding", "Accept-Encoding"),
    /**
     * Authorization
     */
    AUTHORIZATION("Authorization", "Authorization"),
    /**
     * X-Forwarded-For，只有在通过了 HTTP 代理或者负载均衡服务器时才会添加该项
     */
    X_FORWARDED_FOR("X-Forwarded-For", "X-Forwarded-For"),
    /**
     * Proxy-Client-IP，apache http服务器的请求才会添加该项
     */
    PROXY_CLIENT_IP("Proxy-Client-IP", "Proxy-Client-IP"),
    /**
     * WL-Proxy-Client-IP，apache的weblogic插件会添加该项
     */
    WL_PROXY_CLIENT_IP("WL-Proxy-Client-IP", "WL-Proxy-Client-IP"),
    /**
     * HTTP_CLIENT_IP，部分代理服务器会加上此请求头
     */
    HTTP_CLIENT_IP("HTTP_CLIENT_IP", "HTTP_CLIENT_IP"),
    /**
     * X-Real-IP，Nginx代理一般会加上此请求头
     */
    X_REAL_IP("X-Real-IP", "X-Real-IP");

    private final String name;
    private final String desc;

    private static final Map<String, HttpHeaderEnum> LOOKUP;

    static {
        LOOKUP = new HashMap<>();
        for (HttpHeaderEnum httpHeaderEnum : EnumSet.allOf(HttpHeaderEnum.class)) {
            LOOKUP.put(httpHeaderEnum.getName(), httpHeaderEnum);
        }
    }

    HttpHeaderEnum(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    public String getName() {
        return name;
    }

    public String getDesc() {
        return desc;
    }

    public static HttpHeaderEnum findByName(String name) {
        return LOOKUP.get(name);
    }

}
